package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dto.ProNormDto;
import com.example.dto.ProTypeDto;
import com.example.mapper.ProMapper;
import com.example.mapper.ProNormMapper;
import com.example.service.ProNormService;
import com.example.service.ProService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProNormServiceImpl implements ProNormService {
    @Autowired
    private ProNormMapper mapper;
    @Autowired
    private ProMapper proMapper;

    @Override
    public void add(ProNormDto dto) {
        mapper.insert(dto);
    }

    @Override
    public IPage<ProNormDto> select(ProNormDto dto) {
        QueryWrapper<ProNormDto> queryWrapper = new QueryWrapper<>();
        if (dto.getName()!=""&&dto.getName()!=null){
            queryWrapper.eq("name",dto.getName());
        }
        Page<ProNormDto> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        IPage<ProNormDto> result = mapper.selectPage(page, queryWrapper);
        return result;
    }

    @Override
    public void update(ProNormDto dto) {
        QueryWrapper<ProNormDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", dto.getId());
        mapper.update(dto, queryWrapper);
    }

    @Override
    public void delete(ProNormDto dto) {
        QueryWrapper<ProNormDto> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", dto.getId());
        mapper.delete(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> selectName() {
        return mapper.selectName();
    }

}
